//
//  String-style.swift
//  Pods
//
//  Created by zhu xietong on 2017/8/19.
//
//

import Foundation

//private enum JoFont:Int
//{
//    case H6 = 6,H7,H8,H9,H10,H11,H12,H13,H14,H15,H16,H17,H18,H19,H20,H21,H22,H23,H24
//    case H26 = 26
//    case H28 = 28
//    case H30 = 30
//    case H32 = 32
//    case H36 = 36
//    case H42 = 43
//    case H48 = 48
//    
//    public var font:UIFont
//    {
//        get{
//            let v = CGFloat(self.rawValue)
//            return UIFont.systemFont(ofSize: v)
//        }
//    }
//    
//    public var bfont:UIFont
//    {
//        get{
//            let v = CGFloat(self.rawValue)
//            return UIFont.boldSystemFont(ofSize: v)
//        }
//        
//    }
//}

public class StringStyle {
    public var attributes = [NSAttributedString.Key: Any]()
    
    var _lineSpace:CGFloat? = nil
    var _alignmentstyle:NSTextAlignment? = nil
    
    public var onwer:String = ""
    
    public init(onwer:String) {
        self.onwer = onwer
    }

    public init() {
        
    }
    
    public var font10:StringStyle  {return self.addFontSyle(style:.H10)}
    public var font11:StringStyle  {return self.addFontSyle(style:.H11)}
    public var font12:StringStyle  {return self.addFontSyle(style:.H12)}
    public var font13:StringStyle  {return self.addFontSyle(style:.H13)}
    public var font14:StringStyle  {return self.addFontSyle(style:.H14)}
    public var font15:StringStyle  {return self.addFontSyle(style:.H15)}
    public var font16:StringStyle  {return self.addFontSyle(style:.H16)}
    public var font17:StringStyle  {return self.addFontSyle(style:.H17)}
    public var font18:StringStyle  {return self.addFontSyle(style:.H18)}
    public var font19:StringStyle  {return self.addFontSyle(style:.H19)}
    public var font20:StringStyle  {return self.addFontSyle(style:.H20)}
    public var font21:StringStyle  {return self.addFontSyle(style:.H21)}
    public var font22:StringStyle  {return self.addFontSyle(style:.H22)}
    public var font23:StringStyle  {return self.addFontSyle(style:.H23)}
    public var font24:StringStyle  {return self.addFontSyle(style:.H24)}
    public var font28:StringStyle  {return self.addFontSyle(style:.H28)}
    public var font30:StringStyle  {return self.addFontSyle(style:.H30)}
    public var font32:StringStyle  {return self.addFontSyle(style:.H32)}
    public var font36:StringStyle  {return self.addFontSyle(style:.H36)}
    public var font42:StringStyle  {return self.addFontSyle(style:.H42)}
    public var font48:StringStyle  {return self.addFontSyle(style:.H48)}
    
    public var mfont10:StringStyle  {return self.font(font: JoFont.H10.mfont)}
    public var mfont11:StringStyle  {return self.font(font: JoFont.H11.mfont)}
    public var mfont12:StringStyle  {return self.font(font: JoFont.H12.mfont)}
    public var mfont13:StringStyle  {return self.font(font: JoFont.H13.mfont)}
    public var mfont14:StringStyle  {return self.font(font: JoFont.H14.mfont)}
    public var mfont15:StringStyle  {return self.font(font: JoFont.H15.mfont)}
    public var mfont16:StringStyle  {return self.font(font: JoFont.H16.mfont)}
    public var mfont17:StringStyle  {return self.font(font: JoFont.H17.mfont)}
    public var mfont18:StringStyle  {return self.font(font: JoFont.H18.mfont)}
    public var mfont19:StringStyle  {return self.font(font: JoFont.H19.mfont)}
    public var mfont20:StringStyle  {return self.font(font: JoFont.H20.mfont)}
    public var mfont21:StringStyle  {return self.font(font: JoFont.H21.mfont)}
    public var mfont22:StringStyle  {return self.font(font: JoFont.H22.mfont)}
    public var mfont23:StringStyle  {return self.font(font: JoFont.H23.mfont)}
    public var mfont24:StringStyle  {return self.font(font: JoFont.H24.mfont)}
    public var mfont28:StringStyle  {return self.font(font: JoFont.H28.mfont)}
    public var mfont30:StringStyle  {return self.font(font: JoFont.H30.mfont)}
    public var mfont32:StringStyle  {return self.font(font: JoFont.H32.mfont)}
    public var mfont36:StringStyle  {return self.font(font: JoFont.H36.mfont)}
    public var mfont42:StringStyle  {return self.font(font: JoFont.H42.mfont)}
    public var mfont48:StringStyle  {return self.font(font: JoFont.H48.mfont)}
    
    public var lfont10:StringStyle  {return self.font(font: JoFont.H10.lfont)}
    public var lfont11:StringStyle  {return self.font(font: JoFont.H11.lfont)}
    public var lfont12:StringStyle  {return self.font(font: JoFont.H12.lfont)}
    public var lfont13:StringStyle  {return self.font(font: JoFont.H13.lfont)}
    public var lfont14:StringStyle  {return self.font(font: JoFont.H14.lfont)}
    public var lfont15:StringStyle  {return self.font(font: JoFont.H15.lfont)}
    public var lfont16:StringStyle  {return self.font(font: JoFont.H16.lfont)}
    public var lfont17:StringStyle  {return self.font(font: JoFont.H17.lfont)}
    public var lfont18:StringStyle  {return self.font(font: JoFont.H18.lfont)}
    public var lfont19:StringStyle  {return self.font(font: JoFont.H19.lfont)}
    public var lfont20:StringStyle  {return self.font(font: JoFont.H20.lfont)}
    public var lfont21:StringStyle  {return self.font(font: JoFont.H21.lfont)}
    public var lfont22:StringStyle  {return self.font(font: JoFont.H22.lfont)}
    public var lfont23:StringStyle  {return self.font(font: JoFont.H23.lfont)}
    public var lfont24:StringStyle  {return self.font(font: JoFont.H24.lfont)}
    public var lfont28:StringStyle  {return self.font(font: JoFont.H28.lfont)}
    public var lfont30:StringStyle  {return self.font(font: JoFont.H30.lfont)}
    public var lfont32:StringStyle  {return self.font(font: JoFont.H32.lfont)}
    public var lfont36:StringStyle  {return self.font(font: JoFont.H36.lfont)}
    public var lfont42:StringStyle  {return self.font(font: JoFont.H42.lfont)}
    public var lfont48:StringStyle  {return self.font(font: JoFont.H48.lfont)}
    
    public var ulfont10:StringStyle  {return self.font(font: JoFont.H10.ulfont)}
    public var ulfont11:StringStyle  {return self.font(font: JoFont.H11.ulfont)}
    public var ulfont12:StringStyle  {return self.font(font: JoFont.H12.ulfont)}
    public var ulfont13:StringStyle  {return self.font(font: JoFont.H13.ulfont)}
    public var ulfont14:StringStyle  {return self.font(font: JoFont.H14.ulfont)}
    public var ulfont15:StringStyle  {return self.font(font: JoFont.H15.ulfont)}
    public var ulfont16:StringStyle  {return self.font(font: JoFont.H16.ulfont)}
    public var ulfont17:StringStyle  {return self.font(font: JoFont.H17.ulfont)}
    public var ulfont18:StringStyle  {return self.font(font: JoFont.H18.ulfont)}
    public var ulfont19:StringStyle  {return self.font(font: JoFont.H19.ulfont)}
    public var ulfont20:StringStyle  {return self.font(font: JoFont.H20.ulfont)}
    public var ulfont21:StringStyle  {return self.font(font: JoFont.H21.ulfont)}
    public var ulfont22:StringStyle  {return self.font(font: JoFont.H22.ulfont)}
    public var ulfont23:StringStyle  {return self.font(font: JoFont.H23.ulfont)}
    public var ulfont24:StringStyle  {return self.font(font: JoFont.H24.ulfont)}
    public var ulfont28:StringStyle  {return self.font(font: JoFont.H28.ulfont)}
    public var ulfont30:StringStyle  {return self.font(font: JoFont.H30.ulfont)}
    public var ulfont32:StringStyle  {return self.font(font: JoFont.H32.ulfont)}
    public var ulfont36:StringStyle  {return self.font(font: JoFont.H36.ulfont)}
    public var ulfont42:StringStyle  {return self.font(font: JoFont.H42.ulfont)}
    public var ulfont48:StringStyle  {return self.font(font: JoFont.H48.ulfont)}
    
    public var bfont11:StringStyle  {return self.addFontSyle(style:.H11,bold: true)}
    public var bfont12:StringStyle  {return self.addFontSyle(style:.H12,bold: true)}
    public var bfont13:StringStyle  {return self.addFontSyle(style:.H13,bold: true)}
    public var bfont14:StringStyle  {return self.addFontSyle(style:.H14,bold: true)}
    public var bfont15:StringStyle  {return self.addFontSyle(style:.H15,bold: true)}
    public var bfont16:StringStyle  {return self.addFontSyle(style:.H16,bold: true)}
    public var bfont17:StringStyle  {return self.addFontSyle(style:.H17,bold: true)}
    public var bfont18:StringStyle  {return self.addFontSyle(style:.H18,bold: true)}
    public var bfont19:StringStyle  {return self.addFontSyle(style:.H19,bold: true)}
    public var bfont20:StringStyle  {return self.addFontSyle(style:.H20,bold: true)}
    public var bfont21:StringStyle  {return self.addFontSyle(style:.H21,bold: true)}
    public var bfont22:StringStyle  {return self.addFontSyle(style:.H22,bold: true)}
    public var bfont23:StringStyle  {return self.addFontSyle(style:.H23,bold: true)}
    public var bfont24:StringStyle  {return self.addFontSyle(style:.H24,bold: true)}
    public var bfont28:StringStyle  {return self.addFontSyle(style:.H28,bold: true)}
    public var bfont30:StringStyle  {return self.addFontSyle(style:.H32,bold: true)}
    
    public var bfont32:StringStyle  {return self.addFontSyle(style:.H32,bold: true)}
    public var bfont36:StringStyle  {return self.addFontSyle(style:.H36,bold: true)}
    public var bfont42:StringStyle  {return self.addFontSyle(style:.H42,bold: true)}
    public var bfont48:StringStyle  {return self.addFontSyle(style:.H48,bold: true)}
    
    
    
    public var cl_999:StringStyle {return self.color(hex:"#999")}
    public var cl_666:StringStyle {return self.color(hex:"#666")}
    public var cl_333:StringStyle {return self.color(hex:"#333")}
    public var cl_888:StringStyle {return self.color(hex:"#888")}
    public var cl_444:StringStyle {return self.color(hex:"#444")}
    public var cl_222:StringStyle {return self.color(hex:"#222")}
    public var cl_111:StringStyle {return self.color(hex:"#222")}
    
    
    public var cl_fff:StringStyle {return self.color(hex:"#fff")}
    public var cl_000:StringStyle {return self.color(hex:"#000")}
    
    
    public var center:StringStyle {return self.alignment(align: .center)}
    public var right:StringStyle {return self.alignment(align: .right)}
    public var left:StringStyle {return self.alignment(align: .left)}

    
    @discardableResult
    public func alignment(align:NSTextAlignment) ->StringStyle
    {
        self._alignmentstyle = align
        return self
    }
    
    @discardableResult
    private func addFontSyle(style:JoFont,bold:Bool=false) ->StringStyle
    {       
        self.attributes[NSAttributedString.Key.font] = bold ? style.bfont : style.font
        return self
    }
    
    
    @discardableResult
    public func append(_ key:NSAttributedString.Key,_ value:Any) ->StringStyle
    {
        self.attributes[key] = value
        return self
    }
    
    @discardableResult
    public func font(font:UIFont) ->StringStyle
    {
        self.attributes[NSAttributedString.Key.font] = font
        return self
    }
    
    @discardableResult
    public func color(hex:String) ->StringStyle
    {
        self.attributes[NSAttributedString.Key.foregroundColor] = UIColor(shex:hex)
        return self
    }
    
    public func shodow(_ shadow:NSShadow) ->StringStyle
    {
          self.attributes[NSAttributedString.Key.shadow] = shadow
          return self
    }
    
    @discardableResult
    public func color(color:UIColor) ->StringStyle
    {
        self.attributes[NSAttributedString.Key.foregroundColor] = color
        return self
    }

    

    public var astring:NSMutableAttributedString
    {
        get{
            let paragraphStyle = NSMutableParagraphStyle()
            if let space = _lineSpace
            {
                paragraphStyle.lineSpacing = space
            }
            if let align = _alignmentstyle
            {
                paragraphStyle.alignment = align
            }
            attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle

            return NSMutableAttributedString(string: onwer, attributes: attributes)
        }
    }
    public func lineSpace(_ space:CGFloat)->StringStyle
    {
        _lineSpace = space
        return self
    }
    deinit {
    }

    
    
}
extension String{
    
    public func attributedString(style:StringStyle) -> NSMutableAttributedString {
        var attributes = style.attributes
        
        let paragraphStyle = NSMutableParagraphStyle()
        if let space = style._lineSpace
        {
            paragraphStyle.lineSpacing = space
        }
        if let align = style._alignmentstyle
        {
            paragraphStyle.alignment = align
        }
        attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle

        return NSMutableAttributedString(string: self, attributes: attributes)
        
    }
}


public func + (str1:NSMutableAttributedString,str2:NSMutableAttributedString)->NSMutableAttributedString
{
    NSMutableAttributedString(attributedString: str1).append(str2)
    let str = NSMutableAttributedString(attributedString: str1)
    str.append(str2)
    return str
}




extension String{
    public var ui:StringStyle{
        get{
            let str = "\(self)"
            return StringStyle(onwer: str)
        }
        set{
        }
    }
}
